Session["UserName"]

Hi,

I use Session["UserName"] to save and pass values between pages, (please see
the following). It works fine on my computer, but on the server, I launch the
main page, wait for 20 minutes, and click a button to launch User.aspx, it
seems that it cannot see the current value of Session["UserName"]. There's no
problem to launch User.aspx from the main page within 20 minutes. Please
help. Thanks.

//Users.aspx
if (!Page.IsPostBack)
{
if (Convert.ToString(Session["UserName"]) != "")
{
//Do something
}
}
John [ Mo, 14 April 2008 17:09 ] [ ID #1941896 ]

Re: Session["UserName"]

"John" <John [at] discussions.microsoft.com> wrote in message
news:C609B973-6B56-4417-9CB3-5C2225ABDB69 [at] microsoft.com...

> I use Session["UserName"] to save and pass values between pages, (please
> see
> the following). It works fine on my computer, but on the server, I launch
> the
> main page, wait for 20 minutes, and click a button to launch User.aspx, it
> seems that it cannot see the current value of Session["UserName"]. There's
> no
> problem to launch User.aspx from the main page within 20 minutes.

20 minutes is the default time that a session exists before it is torn down
to conserve server resources.

Either increase the session timeout value,
http://www.google.co.uk/search?sourceid=navclient&hl=en-GB&i e=UTF-8&rlz=1T4GZEZ_en-GBGB252GB252&q=Session%2eTimeout

or change your logic...
http://www.google.com/search?q=Session.IsNewSession&rls=com. microsoft:*:IE-Address&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I 7GGIH


--
Mark Rae
ASP.NET MVP
http://www.markrae.net
mark [ Mo, 14 April 2008 17:39 ] [ ID #1941902 ]

Re: Session["UserName"]

Also, the simples way of testing to see if a session variable exists is to
see if it's null or not. Converting it to a string first is a waste. Just do
if(Session["UserName"] != null)
{
Do Something
}

This also helps prevent errors from being thrown if you attempt to convert
upon a null object.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

"John" <John [at] discussions.microsoft.com> wrote in message
news:C609B973-6B56-4417-9CB3-5C2225ABDB69 [at] microsoft.com...
> Hi,
>
> I use Session["UserName"] to save and pass values between pages, (please
> see
> the following). It works fine on my computer, but on the server, I launch
> the
> main page, wait for 20 minutes, and click a button to launch User.aspx, it
> seems that it cannot see the current value of Session["UserName"]. There's
> no
> problem to launch User.aspx from the main page within 20 minutes. Please
> help. Thanks.
>
> //Users.aspx
> if (!Page.IsPostBack)
> {
> if (Convert.ToString(Session["UserName"]) != "")
> {
> //Do something
> }
> }
>
Mark Fitzpatrick [ Mo, 14 April 2008 18:18 ] [ ID #1941906 ]

Re: Session["UserName"]

And managing the user is really a no-brainer when using ASP.NET 2.0


"John" <John [at] discussions.microsoft.com> wrote in message
news:C609B973-6B56-4417-9CB3-5C2225ABDB69 [at] microsoft.com...
> Hi,
>
> I use Session["UserName"] to save and pass values between pages, (please
> see
> the following). It works fine on my computer, but on the server, I launch
> the
> main page, wait for 20 minutes, and click a button to launch User.aspx, it
> seems that it cannot see the current value of Session["UserName"]. There's
> no
> problem to launch User.aspx from the main page within 20 minutes. Please
> help. Thanks.
>
> //Users.aspx
> if (!Page.IsPostBack)
> {
> if (Convert.ToString(Session["UserName"]) != "")
> {
> //Do something
> }
> }
>
Patrice [ Mo, 14 April 2008 21:22 ] [ ID #1941918 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Session["UserName"]

Vorheriges Thema: Retrieving Date & Time from a web server (localhost)
Nächstes Thema: url rewriting and authentication